<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-form
          inline
          size="small"
          :model="tableFrom"
          ref="tableFrom"
          label-width="100px"
        >
          <el-form-item label="数据场：">
            <!-- <el-input v-model="tableFrom.userId" placeholder="请选择用户UID" @focus="selectUser" clearable
              class="selWidth" /> -->
            <UserSearchable
              v-model="tableFrom.dataFactoryId"
              :type="'datafieldList'"
            >
              <template #dropdownTitle>
                <span>数据场</span>
              </template>
              <template v-slot:dropdown="{ item }">
                <span>{{ item.name }}</span>
              </template>
            </UserSearchable>
            <!-- <UserSearchable v-model="tableFrom.userId" type=""></UserSearchable> -->
          </el-form-item>
          <el-form-item label="开始时间：">
            <el-date-picker
              v-model="tableFrom.startTime"
              type="date"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
              placeholder="选择日期"
              clearable
              class="selWidth"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="结束时间：">
            <el-date-picker
              v-model="tableFrom.endTime"
              type="date"
              value-format="yyyy-MM-dd"
              format="yyyy-MM-dd"
              placeholder="选择日期"
              clearable
              class="selWidth"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button
              class="mr10"
              size="small"
              type="primary"
              @click="search()"
              >搜索</el-button
            >
            <el-button class="mr10" size="small" @click="reset()"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <el-table
        border
        v-loading="listLoading"
        :data="tableData.data"
        style="width: 100%"
        size="mini"
        class="table"
        highlight-current-row
      >
        <el-table-column
          prop="dataFactoryName"
          label="数据场"
          min-width="100"
        />
        <el-table-column prop="totalEntry" label="总进账" min-width="100" />
        <el-table-column prop="intoDetail" label="进账明细" min-width="100">
          <template slot-scope="scope">
            <el-table :data="scope.row.intoDetail">
              <el-table-column prop="detailName" label="名称" min-width="100" />
              <el-table-column
                prop="detailPrice"
                label="金额"
                min-width="100"
              />
            </el-table>
          </template>
        </el-table-column>
        <el-table-column prop="generalAccount" label="总出账" min-width="100" />
        <el-table-column prop="intoDetail" label="出账明细" min-width="100">
          <template slot-scope="scope">
            <el-table :data="scope.row.intoDetail">
              <el-table-column prop="detailName" label="名称" min-width="100" />
              <el-table-column
                prop="detailPrice"
                label="金额"
                min-width="100"
              />
            </el-table>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="approvalStatus" label="状态" min-width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.approvalStatus == 1">待审核</span>
            <span v-if="scope.row.approvalStatus == 2">已通过</span>
            <span v-if="scope.row.approvalStatus == 3">已拒绝</span>
          </template>
        </el-table-column> -->
        <!-- <el-table-column prop="approvalDate" label="审核时间" min-width="200" /> -->
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>

    <!--用户列表-->
    <el-dialog
      title="用户列表"
      :visible.sync="userVisible"
      width="900px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <user-list
        v-if="userVisible"
        @getTemplateRow="getTemplateRow"
      ></user-list>
      <span slot="footer" class="dialog-footer">
        <el-button @click="userclose()">取 消</el-button>
        <el-button type="primary" @click="usersubmit()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { walletBillDataField } from "@/api/financial";
import userList from "@/components/userList";

import UserSearchable from "@/components/UserSearchable";

export default {
  components: {
    userList,
    UserSearchable,
  },
  data() {
    return {
      userVisible: false,
      cardLists: [],
      tableFrom: {
        userId: "",
        startTime: "",
        endTime: "",
        page: 1,
        limit: 20,
      },
      listLoading: false,
      tableData: {
        data: [],
        total: 0,
      },
    };
  },
  mounted() {
    this.getlist();
  },
  methods: {
    selectUser() {
      this.userVisible = true;
    },
    getTemplateRow(row) {
      this.tableFrom.userId = row.uid;
    },
    userclose() {
      this.tableFrom.userId = "";
      this.userVisible = false;
    },
    usersubmit() {
      this.userVisible = false;
    },
    search() {
      this.tableFrom.page = 1;
      this.tableFrom.limit = 15;
      this.getlist();
    },
    reset() {
      this.tableFrom = {
        userId: "",
        startTime: "",
        endTime: "",
        page: 1,
        limit: 20,
      };
      this.getlist();
    },
    getlist() {
      this.listLoading = true;
      walletBillDataField(this.tableFrom)
        .then((res) => {
          this.tableData.data = res.list;
          this.tableData.total = res.total;
          this.listLoading = false;
        })
        .catch(() => {
          this.listLoading = false;
        });
    },
    pageChange(page) {
      this.tableFrom.page = page;
      this.getlist();
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val;
      this.getlist();
    },
  },
};
</script>

<style lang="scss" scoped></style>
